package com.hgx.springcloud.paymenthystrix.controller;

import com.hgx.springcloud.common.entities.response.CommonResultResponse;
import com.hgx.springcloud.paymenthystrix.entities.Payment;
import com.hgx.springcloud.paymenthystrix.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;
    @Value("${server.port}")
    private String serverPort;


    @GetMapping("/payment/ok/{id}")
    public String ok(@PathVariable("id") String id) {
        String ok = paymentService.ok(id);
        log.info(ok);
        return ok + "\t" + serverPort;
    }


    @GetMapping("/payment/timeout/{id}")
    public String timeout(@PathVariable("id") String id) {
        String timeout = paymentService.timeOut(id);
        log.info(timeout);
        return timeout + "\t" + serverPort;
    }

    @GetMapping("/payment/circuitBreaker/{id}")
    public String circuitBreaker(@PathVariable("id") String id) {
        String circuitBreaker = paymentService.circuitBreaker(id);
        log.info(circuitBreaker);
        return circuitBreaker + "\t" + serverPort;
    }

}
